﻿using System;
using System.Linq;
using System.Reflection;

namespace NativeCode.Core.Extensions
{
	public static class ObjectExtensions
	{
		public static T GetPropertyValue<T>(this object instance, string propertyName)
		{
			Type type = instance.GetType();
			PropertyInfo property = type.GetProperties().FirstOrDefault(p => p.Name == propertyName);
			if (property != null)
			{
				return (T) property.GetValue(instance, new object[] {});
			}

			return default(T);
		}
	}
}